﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LuckyLoot.Presentation.BasePage;
using LuckyLoot.ServiceFacade.Contracts;
using LuckyLoot.ServiceFacade.Implementation;

namespace LuckyLoot.Presentation
{
    public partial class _Default : LuckyLootPage
    {
        private IReminderService _reminderService;
        public IReminderService ReminderService
        {
            get
            {
                if (_reminderService == null)
                    _reminderService = new ReminderService();

                return _reminderService;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            var lowStockSupplies = ReminderService.LowStockSupplies();
            var expiringSupplies = ReminderService.ExpiringSupplies();
            var expiringSterilizationTools = ReminderService.ExpiringSterilizationTools();
            var weekAppointments = ReminderService.WeekAppointments();

            if (lowStockSupplies.Count() > 0)
            {
                this.LowStockSuppliesGrid.DataSource = lowStockSupplies;
                this.LowStockSuppliesGrid.DataBind();
                this.LowStockSuppliesGrid.Visible = true;
                this.LowStockSuppliesLabel.Visible = true;
            }

            if (expiringSupplies.Count() > 0)
            {
                this.ExpiringSuppliesGrid.DataSource = expiringSupplies;
                this.ExpiringSuppliesGrid.DataBind();
                this.ExpiringSuppliesGrid.Visible = true;
                this.ExpiringSuppliesLabel.Visible = true;
            }

            if (expiringSterilizationTools.Count() > 0)
            {
                this.ExpiringSterilizationToolsGrid.DataSource = expiringSterilizationTools;
                this.ExpiringSterilizationToolsGrid.DataBind();
                this.ExpiringSterilizationToolsGrid.Visible = true;
                this.ExpiringSterilizationToolsLabel.Visible = true;
            }

            if (weekAppointments.Count() > 0)
            {
                this.WeekAppointmentsGrid.DataSource = weekAppointments;
                this.WeekAppointmentsGrid.DataBind();
                this.WeekAppointmentsGrid.Visible = true;
                this.WeekAppointmentLabel.Visible = true;
            }
        }
    }
}
